package com.shujia.mr.DianXin3;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.ArrayList;

public class DianXinReducer3 extends Reducer<Text,Text,Text,Text> {
    @Override
    protected void reduce(Text key, Iterable<Text> values, Reducer<Text, Text, Text, Text>.Context context) throws IOException, InterruptedException {
        String cityName = null;
        ArrayList<String> list = new ArrayList<>();
        for (Text value : values) {
            String infos = value.toString();
            if (infos.startsWith("*")) {
                list.add(infos.substring(1));
            }else if (infos.startsWith("#")){
                cityName = infos.substring(1);
            }
        }
        for (String s : list) {
            String[] info = s.split("-");
            String phoneNumber = info[0];
            String date = info[1];
            context.write(new Text(phoneNumber+cityName),new Text(date));
        }
    }
}
